﻿Imports System.Data.OleDb

Partial Public Class AddUserInfo
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnSave.Click

        Dim Conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString())
        Dim ID_string As String = " SELECT [UserID] FROM aspnet_Users WHERE UserName = '" & User.Identity.Name & "' "
        Dim findIDCmd As New OleDbCommand(ID_string, Conn)
        Conn.Open()
        Dim ID As OleDbDataReader = findIDCmd.ExecuteReader
        ID.Read()
        Dim UserID As Integer = ID("UserID")

        Dim sql As String = "INSERT INTO UserDetails (UserID_FK, FirstName, LastName, Country, [image], occupation, Occ_Desc, aboutuser) VALUES (@UserID_FK, @FirstName, @LastName, @Country, [@image], @occupation, @Occ_Desc, @aboutuser)"

        Dim fileLocationOnServer = Request.MapPath("Images/Users/" & FileUpload1.FileName)
        FileUpload1.SaveAs(fileLocationOnServer)
        Dim imagepath As String = "Images/Users/" & FileUpload1.FileName

        Dim cmd As New OleDbCommand(sql, Conn)
        cmd.Parameters.AddWithValue("@UserID_FK", UserID)
        cmd.Parameters.AddWithValue("@FirstName", TextBox1.Text)
        cmd.Parameters.AddWithValue("@LastName", TextBox2.Text)
        cmd.Parameters.AddWithValue("@Country", DropDownList1.SelectedValue.ToString)
        cmd.Parameters.AddWithValue("@Image", imagepath)
        cmd.Parameters.AddWithValue("@occupation", TextBox3.Text)
        cmd.Parameters.AddWithValue("@Occ_Desc", TextBox4.Text)
        cmd.Parameters.AddWithValue("@aboutuser", TextBox5.Text)
        cmd.ExecuteNonQuery()
        Conn.Close()

        Response.Redirect("./list.aspx")
    End Sub
End Class